package cn.wolfcode.config;

import cn.wolfcode.web.interceptor.HelloInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
//创建对象,因为实现这个WebMvcConfigurer 创建对象之后会调用下面这个addInterceptors
//帮我们配置拦截器
public class MvcJavaConfig implements WebMvcConfigurer {

    //在拦截器中贴标签 自动注入拦截器对象
    @Autowired
    private HelloInterceptor helloInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器把拦截器当值
        registry.addInterceptor(helloInterceptor)
                //添加拦截路径 (针对所有路径)
                .addPathPatterns("/**")
                //排出路径(注意登录是要把登录页面排除)
                .addPathPatterns("/static/**");


    }
}
